package com.wealth.scsj.p_app.view.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.wealth.scsj.p_app.R;
import com.wealth.scsj.p_app.adapter.OrderIndexAdapter;
import com.wealth.scsj.p_app.bean.OrderIndexBean;
import com.wealth.scsj.p_app.mydefinedview.payeditview.VerificationCodeView;
import com.wealth.scsj.p_app.utils.DialogUtils;
import com.wealth.scsj.p_app.utils.SkipUtils;
import com.wealth.scsj.p_app.view.activity.depositmodel.DepositHomePageActivity;

import java.util.ArrayList;
import java.util.List;

import es.dmoral.toasty.Toasty;

/**
 * 配送中
 */
public class SendFragment extends BaseFragment {

    private RecyclerView send_rv;
    private List<OrderIndexBean> orderIndexBeanList;
    private OrderIndexAdapter adapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_send, null);
        initView(inflate, null);
        initData();
        return inflate;
    }


    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        send_rv = view.findViewById(R.id.send_rv);
        send_rv.setLayoutManager(new LinearLayoutManager(getHoldingActivity()));
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        orderIndexBeanList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            orderIndexBeanList.add(new OrderIndexBean("fff", "fff", "fff", "fff", "fff", "fff", "fff", "fff"));
        }
        adapter = new OrderIndexAdapter(orderIndexBeanList);
        send_rv.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

//                Toasty.info(getHoldingActivity(), "点击了"+position).show();
//                showPayWindow();
//                view.findViewById(R.id.order_detail_tv).setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        SkipUtils.toOrderDetail(getHoldingActivity());
//                    }
//                });
//
//                view.findViewById(R.id.contact_tv).setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        Toasty.info(getHoldingActivity(), "点击了联系买家").show();
//                    }
//                });
//                (view.findViewById(R.id.make_sure_tv)).setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//
//                    }
//                });
            }
        });

        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {

//                if(view.getId()==R.id.order_detail_tv){
//                    SkipUtils.toOrderDetail(getHoldingActivity());
//                }else if(view.getId()==R.id.contact_tv){
//                    Toasty.info(getHoldingActivity(), "点击了联系买家").show();
//                }else if(view.getId()==R.id.make_sure_tv){
                    Toasty.info(getHoldingActivity(), "点击了确认送达").show();
                    showPayWindow();
//                }

            }
        });
    }

    @Override
    protected int getLayoutId() {
        return 0;
    }


    private void showPayWindow() {
        DialogUtils.getInstance()
                .with(getHoldingActivity())//上下文
                .setlayoutId(R.layout.receipt_code_dialog)//布局文件  choose_pay_type_layout
                .setlayoutPosition(Gravity.CENTER)//位置
                .setlayoutAnimaType(0)//动画类型:0自下而上动画，1淡入淡出动画
                .setlayoutPading(60, 0, 60, 0)//与屏幕距离
                .setOnChildViewclickListener(new DialogUtils.ViewInterface() {
                    @Override
                    public void getChildView(View view, int layoutResId) {
                        //处理dialog内部控件的点击事件
                        //TextView callNoticeTv = view.findViewById(R.id.call_notice_tv);

                        view.findViewById(R.id.cancel_pop_iv).setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                DialogUtils.dismiss();
                            }
                        });
                        final VerificationCodeView mCodeView = (VerificationCodeView)view.findViewById(R.id.icv);
                        mCodeView.setInputCompleteListener(new VerificationCodeView.InputCompleteListener() {
                            @Override
                            public void inputComplete() {//输入完毕
                                //TODO 此处可以添加 验证码是否正确的判断
                                if(mCodeView.getInputContent().length()==6){
                                    DialogUtils.dismiss();
                                }
                            }

                            @Override
                            public void deleteContent() {

                            }
                        });
                    }
                })
                .show();
    }
}
